package com.hm.manage.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hm.common.annotation.Log;
import com.hm.common.core.controller.BaseController;
import com.hm.common.core.domain.AjaxResult;
import com.hm.common.enums.BusinessType;
import com.hm.manage.domain.CameraDelRecord;
import com.hm.manage.service.ICameraDelRecordService;
import com.hm.common.utils.poi.ExcelUtil;
import com.hm.common.core.page.TableDataInfo;

/**
 * 点位删除记录Controller
 * 
 * @author hm
 * @date 2025-03-27
 */
@RestController
@RequestMapping("/manage/cameraDelRecord")
public class CameraDelRecordController extends BaseController
{
    @Autowired
    private ICameraDelRecordService cameraDelRecordService;

    /**
     * 查询点位删除记录列表
     */
    @PreAuthorize("@ss.hasPermi('manage:cameraDelRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(CameraDelRecord cameraDelRecord)
    {
        startPage();
        List<CameraDelRecord> list = cameraDelRecordService.selectCameraDelRecordList(cameraDelRecord);
        return getDataTable(list);
    }

    /**
     * 导出点位删除记录列表
     */
    @PreAuthorize("@ss.hasPermi('manage:cameraDelRecord:export')")
    @Log(title = "点位删除记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CameraDelRecord cameraDelRecord)
    {
        List<CameraDelRecord> list = cameraDelRecordService.selectCameraDelRecordList(cameraDelRecord);
        ExcelUtil<CameraDelRecord> util = new ExcelUtil<CameraDelRecord>(CameraDelRecord.class);
        util.exportExcel(response, list, "点位删除记录数据");
    }

    /**
     * 获取点位删除记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:cameraDelRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cameraDelRecordService.selectCameraDelRecordById(id));
    }

    /**
     * 新增点位删除记录
     */
    @PreAuthorize("@ss.hasPermi('manage:cameraDelRecord:add')")
    @Log(title = "点位删除记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CameraDelRecord cameraDelRecord)
    {
        // 试试mybatisplus的插入方法
//        cameraDelRecordService.save(cameraDelRecord);
//        return success();
        return toAjax(cameraDelRecordService.insertCameraDelRecord(cameraDelRecord));
    }

    /**
     * 修改点位删除记录
     */
    @PreAuthorize("@ss.hasPermi('manage:cameraDelRecord:edit')")
    @Log(title = "点位删除记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CameraDelRecord cameraDelRecord)
    {
        return toAjax(cameraDelRecordService.updateCameraDelRecord(cameraDelRecord));
    }

    /**
     * 删除点位删除记录
     */
    @PreAuthorize("@ss.hasPermi('manage:cameraDelRecord:remove')")
    @Log(title = "点位删除记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        // 用mybatisplus的删除方法
        //cameraDelRecordService.deleteBatchIds(Arrays.asList(ids));
        return toAjax(cameraDelRecordService.deleteCameraDelRecordByIds(ids));
    }
}
